﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using orienta.Models;
using System.Web.Security;
using System.ComponentModel.DataAnnotations;
using System.Text;

namespace orienta.Controllers
{
    [Authorize]
    public class OrientaController : Controller
    {
        //
        // GET: /Orienta/
        protected ORIMaeUsuario usuario = null;
        private String vCodUsuario = null;
        private int nIdeUsu = 0;
        private int nIdeDep = 0;
        private int nIdeFuncionario = 0;
        protected int nIdeRegion = 0;
        protected String v = null;
//        protected decimal nIdeUser = 0;

        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (filterContext.HttpContext.Session != null && !HttpContext.Request.IsAjaxRequest())
            {
                
                if (
                    //(!(filterContext.Controller is EstadisticaController && filterContext.ActionDescriptor.Equals("Reporte"))) && 
                    filterContext.HttpContext.Session["MENU_ITEMS1"] != null)
                    filterContext.Result =
                            RedirectToAction("Index", "Home");
                //return;
                /*
                if (filterContext.HttpContext.Session.IsNewSession)
                {
                    string cookie = filterContext.HttpContext.Request.Headers["Cookie"];
                    if ((cookie != null) && (cookie.IndexOf("_sessionId") >= 0))
                    {
                        filterContext.Result =
                            RedirectToAction("Index", "Home");
                        return;
                    }
                }*/
            }
            base.OnActionExecuting(filterContext);
        }

        public Boolean validar(String user) {

            if (user != null)
            {
                String[] arr = user.Split('@');
                vCodUsuario = arr[0];
                nIdeUsu = Int32.Parse(arr[1]);
                nIdeDep = Int32.Parse(arr[2]);
                nIdeFuncionario= Int32.Parse(arr[4]);
                nIdeRegion = Int32.Parse(arr[5]);
                usuario = new ORIMaeUsuario();
                usuario.vCodUsuario = vCodUsuario;
                usuario.nIdeUsu = nIdeUsu;
                usuario.nIdeDep = nIdeDep;
                usuario.nIdeFuncionario = nIdeFuncionario;

                return true;
            }
            else
                return false;
            //Objetct o1 = Page
            
        }

       

        protected ActionResult ReturnPartialView(string viewName, object model = null)
        {
            //ViewBag.MENU_ITEMS = Menu_Items;
            return model == null ? PartialView(viewName) : PartialView(viewName, model);
        }
        protected ActionResult ReturnPartialView()
        {
            //ViewBag.MENU_ITEMS = Menu_Items;
            return PartialView();
        }


           /*   
        public virtual ActionResult Index(){
             if (User.Identity.Name == null)
            {
                return RedirectToAction("Logon", "Account");
            }else
                 return View();

        }*/
            


    }
}
